<?php

class message extends db {

	function message() {
		$this->db();
	}
	
	function get_messages($user_id=0, $sort='title', $direction='ASC', $start=0, $offset=0) {
		$sql = "SELECT * FROM message";

		if($user_id != 0) {
			$where = true;
			$sql .= " WHERE uid = '$user_id' AND is_deleted = 'F'";
		}

		$sql .= " ORDER BY $sort $direction";

		$this->query($sql);
		$count = $this->num_rows();

		if ($offset > 0 && $count > $offset) {
//			echo $sql." LIMIT $start, $offset";
//			exit;
			$this->query($sql." LIMIT $start, $offset");
		}
		return $count;
	}
	
	function get_message($msg_id) {
		$sql = "SELECT * FROM message WHERE id = '$msg_id'";
		$this->query($sql);
		if ($this->next_record()) {
			return $this->Record;
		}
		return false;
	}
	
	function delete_message($msg_id) {
		$sql = "UPDATE message SET is_deleted = 'T' WHERE id = '$msg_id'";
		return $this->query($sql);
	}
}
?>